<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar
      title="站内信"
      left-arrow
      :border="false"
      fixed
      @click-left="$utils.back($route.path);"
    />
    <div class="has-top"></div>

    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <!-- 站内信列表 -->
      <van-list
        v-model="loading"
        :finished="finished"
        :finished-text="messageList.length > 0?'没有更多了哦！':''"
        :offset="10"
        @load="onLoad"
        :immediate-check="false"
        ref="list"
      >
        <van-cell-group v-if="messageList.length > 0">
          <van-cell
            icon="envelop-o"
            clickable
            v-for="(item,index) in messageList"
            :key="index"
            :to="{path:'/home/messageInfo/' + item.Id}"
            is-link
          >
            <span slot="title">{{item.Title}}</span>
            <span slot="label">{{item.AddTime}}</span>
          </van-cell>
        </van-cell-group>
        <no-data v-if="messageList.length == 0 && !loading" />
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { getPageList } from 'api/siteMessage'
import noData from 'components/noData'

export default {
  components: {
    noData
  },
  data() {
    return {
      // 下拉刷新
      isLoading: false,
      // 上拉加载更多
      loading: true,
      finished: false,
      modelCondition: {
        PageIndex: 1,
        PageSize: 10
      },
      messageList: []
    }
  },
  methods: {
    // 下拉刷新
    onRefresh() {
      this.messageList = []
      this.loading = true
      this.modelCondition.PageIndex = 1
      this.getPageList()
    },
    // 上拉异步加载更多
    onLoad() {
      //console.log("加载更多");
      this.modelCondition.PageIndex = this.modelCondition.PageIndex + 1
      this.getPageList()
    },
    // 获取站内信列表
    getPageList() {
      getPageList(this.modelCondition).then(res => {
        //console.log(res);
        if (res) {
          this.messageList = this.messageList.concat(res.Data)
          this.isLoading = false
          if (this.modelCondition.PageIndex < res.TotalAmout) {
            this.loading = false
            this.finished = false
            // 检测是否到底加载更多
            this.$refs['list'].check()
          } else {
            this.loading = false
            this.finished = true
          }
        }
      })
    }
  },
  created() {
    this.getPageList()
  }
}
</script>

<style lang="scss" scoped>
</style>
